﻿namespace WebApiTest1.Middlewares
{
    public class ConventionalMiddleware
    {
        private readonly RequestDelegate _next;

        public ConventionalMiddleware(RequestDelegate next)
            => _next = next;

        ////在这里的参数有方法的依赖注入
        //public async Task InvokeAsync(HttpContext context, SampleDbContext dbContext)
        //{
        //    var keyValue = context.Request.Query["key"];

        //    if (!string.IsNullOrWhiteSpace(keyValue))
        //    {
        //        dbContext.Requests.Add(new Request("Conventional", keyValue));

        //        await dbContext.SaveChangesAsync();
        //    }

        //    await _next(context);
        //}

        public async Task InvokeAsync(HttpContext context)
        {
            var keyValue = context.Request.Query["key"];

            if (!string.IsNullOrWhiteSpace(keyValue))
            {
                //dbContext.Requests.Add(new Request("Conventional", keyValue));

                //await dbContext.SaveChangesAsync();
            }

            await _next(context);
        }
    }
   
}
